package com.example.zhuyu.basecommon.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.zhuyu.basecommon.R;

/**
 * @author zhuyu
 * @date 2019/3/12
 * @desc
 */
public class ItemView extends RelativeLayout {

    private String mLeft;
    private String mRight;

    public ItemView(Context context) {
        super(context,null);

    }

    public ItemView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ItemView);
        String itemType = ta.getString(R.styleable.ItemView_itemType);
        mLeft = ta.getString(R.styleable.ItemView_leftText);
        mRight = ta.getString(R.styleable.ItemView_rightText);
        initLayout(itemType,context);
        ta.recycle();
    }

    public ItemView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }

    private void initLayout(String itemType,Context context) {

        if(TextUtils.equals(itemType,"s1")){
            View view = LayoutInflater.from(context).inflate(R.layout.item_layout_s1, this);
            TextView left = view.findViewById(R.id.tv_left);
            TextView right = view.findViewById(R.id.tv_right);
            left.setText(mLeft);
            right.setText(mRight);
        }
    }

}
